<?php
namespace Home\Controller;
use Think\Controller;
class OrderController extends CommonController {
    public function data_list(){
        $limit = I("pageSize", 30, "intval");
        $page = I("pageCurrent", 1, "intval");
        $search_words = I('search_words');
        $search_account = I('search_account');
        if($search_words!=null&&$search_words!=''){
            $condition['or_serial_number'] = array('like','%'.$search_words.'%');
        }
        if($search_account!=null&&$search_account!=''){
            $condition['or_account'] = array('like','%'.$search_account.'%');
        }
        if(I('or_status')!=null&&I('or_status')!=''){
            $condition['or_status'] = array('eq',I('or_status'));
        }
        if(I('us_id')!=null&&I('us_id')!=''){
            $condition['or_user_id'] = array('eq',I('us_id'));
            $this->assign('or_user_id',I('us_id'));
        }

        $orderField = I("orderField", "or_id");
        $orderDirection = I("orderDirection", "desc");
        if($orderField==''){
            $orderField = "or_id";
        }
        if($orderDirection==''){
            $orderDirection = "desc";
        }

        $this->assign('search_words',$search_words);
        $order_model = D("Order");
        $count = $order_model->get_count($condition);
        $dataList = $order_model->get_order_list($condition, $limit, $page,"*",$orderField.' '.$orderDirection);
        $this->assign("count",$count);
        $this->assign("dataList",$dataList);
        $this->display();
    }
    /*统一充值*/
    public function unifiedRecharge(){
        if(IS_POST){
            $money = I("money",0,"intval");
            $order_model = D("Order");
            $user_model = D("User");
            $condition = array(
                'or_status'=>array('neq',2)
            );
            $datList = $order_model->field('or_user_id')->where($condition)->select();
            foreach ($datList as $key => $value) {
                $userfind = array(
                    'us_id'=>$value['or_user_id']
                );
                $user = $user_model->where(array('us_id'=>$value['or_user_id']))->find();
                if(!empty($user)){
                    M('User')->where(array('us_id'=>$user['us_id']))->save(array('us_award_money'=>((int)$user['us_award_money']+$money)));
                    M('awardLog')->add(array(
                        'aw_value'=>$money,
                        'aw_target'=>$user['us_id'],
                        'aw_source'=>0,
                        'aw_create_time'=>time()
                    ));
                }
            }
            exit(success('成功！',true));
        }else{
            $this->display();
        }
    }

    public function order_log_list(){
        $limit = I("pageSize", 30, "intval");
        $page = I("pageCurrent", 1, "intval");
        $order_id = I('order_id');
        $condition['ol_order_id'] = $order_id;
        $orderLog_model = D("OrderLog");
        $count = $orderLog_model->get_count($condition);
        $dataList = $orderLog_model->get_orderLog_list($condition, $limit, $page);
        $this->assign("count",$count);
        $this->assign("dataList",$dataList);
        $this->display();
    }
}